Skip to content

[CHANGE] Reuse the same request session on same instance - #110

Merged
pablo-estevez-lrn merged 5 commits into
masterfrom
reuse-same-request-session
Oct 16, 2026
Merged

pablo-estevez-lrn merged 5 commits into
masterfrom
reuse-same-request-session

Conversation

@pablo-estevez-lrn

@pablo-estevez-lrn pablo-estevez-lrn commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor
  • Reuse the same request session on the same Data API instance
  • Added a close() public method to close the session

Checklist

  • Feature

  • Bug

  • Security

  • Documentation

  • ChangeLog.md updated

  • Tests added

  • All testsuites passed

  • make dist completed successfully

  • Bump package version if release coming

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Session cleanup needs a deterministic public API, and the reuse behavior lacks regression coverage.

3 open findings
What changed in this PR

Reuses one HTTP session per DataApi instance to enable connection pooling.

Changes:

  • Adds session creation and cleanup.
  • Routes requests through the shared session.
  • Updates the changelog.
File Description
learnosity_sdk/​request/​dataapi.py Introduces and uses a shared request session.
ChangeLog.md Records session reuse.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread learnosity_sdk/request/dataapi.py Outdated
Comment thread ChangeLog.md Outdated
Comment thread learnosity_sdk/request/dataapi.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

Core behavior is correctly tested; only a minor public-API documentation clarification remains.

1 open finding
3 resolved since last review

🧠 Review effort: Balanced

Comment thread learnosity_sdk/request/dataapi.py
@pablo-estevez-lrn pablo-estevez-lrn changed the title [CHANGE] Eeuse the same request session on same instance [CHANGE] Reuse the same request session on same instance Oct 13, 2026
Add docstring to the close method for clarity.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@michael-linnane-lrn michael-linnane-lrn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pablo-estevez-lrn, two comments. We need to be careful when altering existing classes since we don't know how the integrations might be used already. Should be easy to fix with backwards compatibility though

Comment thread learnosity_sdk/request/dataapi.py Outdated
Comment on lines +66 to +68
session = getattr(self, '_session', None)
if session is not None:
session.close()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Question: Why allow later requests? Would we not just fully drop it and have an actual blank slate?

Suggested change
session = getattr(self, '_session', None)
if session is not None:
session.close()
if getattr(self, '_session', None) is not None:
self._session.close()
self._session = None

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 reasons:

  1. To avoid an invalid state after close(), when we raise an error None does not have an attribute post. (after the last commit, will be creating a new session instead)
  2. To use the same known semantic that requests, where close is closing the transport, but not converting to a blank slate.
    If you want to destroy the object, you can always use del()

it will be functionally equivalent, so happy to change if you want

@michael-linnane-lrn michael-linnane-lrn Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't cookies persist through into the reuse?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its okay to sink the above btw, just probably worth adding a note in the docstring that certain values will persist even after closing

Comment thread learnosity_sdk/request/dataapi.py Outdated
@michael-linnane-lrn

Copy link
Copy Markdown
Contributor

Thanks Pablo. The only overarching comment I have is that session is a Learnosity term so there could (unlikely) have been some clients using it already i.e. in the same way I said before but having it set to a session_id for instance e.g. self._session = session_id. Would we be safer calling this _http_session?

@pablo-estevez-lrn

Copy link
Copy Markdown
Contributor Author

Thanks Pablo. The only overarching comment I have is that session is a Learnosity term so there could (unlikely) have been some clients using it already i.e. in the same way I said before but having it set to a session_id for instance e.g. self._session = session_id. Would we be safer calling this _http_session?
Yes, probably better to call it _http_session, just in case. changed on 606538d

@pablo-estevez-lrn
pablo-estevez-lrn merged commit fb02828 into master Oct 16, 2026
7 of 8 checks passed
@pablo-estevez-lrn
pablo-estevez-lrn deleted the reuse-same-request-session branch October 16, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants